home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / PROGRAMS / CH7 / 7-4-4.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-09-19  |  2.6 KB  |  91 lines

  1. VERSION 5.00
  2. Begin VB.Form frm7_4_4 
  3.    Caption         =   "Parts of a Running Shoe"
  4.    ClientHeight    =   1572
  5.    ClientLeft      =   1056
  6.    ClientTop       =   2160
  7.    ClientWidth     =   6912
  8.    BeginProperty Font 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   7.8
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    LinkTopic       =   "Form1"
  18.    PaletteMode     =   1  'UseZOrder
  19.    ScaleHeight     =   1572
  20.    ScaleWidth      =   6912
  21.    Begin VB.PictureBox picParts 
  22.       Height          =   855
  23.       Left            =   120
  24.       ScaleHeight     =   804
  25.       ScaleWidth      =   6564
  26.       TabIndex        =   1
  27.       Top             =   600
  28.       Width           =   6612
  29.    End
  30.    Begin VB.CommandButton cmdDisplayParts 
  31.       Caption         =   "Display Shoe Parts in Alphabetical Order"
  32.       Height          =   375
  33.       Left            =   1440
  34.       TabIndex        =   0
  35.       Top             =   120
  36.       Width           =   4095
  37.    End
  38. Attribute VB_Name = "frm7_4_4"
  39. Attribute VB_GlobalNameSpace = False
  40. Attribute VB_Creatable = False
  41. Attribute VB_PredeclaredId = True
  42. Attribute VB_Exposed = False
  43. Dim part(1 To 50) As String
  44. Dim numParts As Integer
  45. Private Sub cmdDisplayParts_Click()
  46.   'Sort and display parts of running shoe
  47.   Call SortData
  48.   Call ShowData
  49. End Sub
  50. Private Sub Form_Load()
  51.   'Read part names
  52.   numParts = 0    'Number of parts
  53.   Open App.Path & "\SHOEPART.TXT" For Input As #1
  54.   Do While (Not EOF(1)) And (numParts < UBound(part))
  55.     numParts = numParts + 1
  56.     Input #1, part(numParts)
  57.   Loop
  58.   Close #1
  59. End Sub
  60. Private Sub ShowData()
  61.   Dim i As Integer
  62.   'Display sorted list of parts
  63.   picParts.Cls
  64.   For i = 1 To numParts
  65.     picParts.Print part(i),
  66.     If i Mod 5 = 0 Then  'only put 5 items per line
  67.         picParts.Print
  68.     End If
  69.   Next i
  70. End Sub
  71. Private Sub SortData()
  72.   Dim gap As Integer, doneFlag As Boolean
  73.   Dim index  As Integer, temp As String
  74.   'Shell sort shoe parts
  75.   gap = Int(numParts / 2)
  76.   Do While gap >= 1
  77.     Do
  78.       doneFlag = True
  79.       For index = 1 To numParts - gap
  80.         If part(index) > part(index + gap) Then
  81.             temp = part(index)
  82.             part(index) = part(index + gap)
  83.             part(index + gap) = temp
  84.             doneFlag = False
  85.         End If
  86.       Next index
  87.     Loop Until doneFlag = True  'Can be written  Loop Until doneFlag
  88.     gap = Int(gap / 2)       'Halve the length of the gap
  89.   Loop
  90. End Sub
  91.